// subPackages/packageA/shesu/components/statisTable/statisTable.ts
import { getSxStatAmountListAPI, getSxStatCountListAPI } from "../../../api/shesu"
import { debtorPrice } from "../../../../../utils/util"
Component({
  options: {
    styleIsolation: "apply-shared"
  },
  /**
   * 组件的属性列表
   */
  properties: {
    debtorId: {
      type: String,
      value: ""
    },
    businessType: {
      type: String,
      value: "1"
    },
    typeName: {
      type: String, // count, amount
      value: "count"
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    tableData: []
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 案件金额统计
    async getSxStatAmountList() {
      let { content }: any = await getSxStatAmountListAPI({ id: this.data.debtorId, businessType: this.data.businessType })
      this.data.tableData = content.map(item => {
        item.accuserNum = debtorPrice(item.accuserNum)
        item.accusedNum = debtorPrice(item.accusedNum)
        item.thirdManNum = debtorPrice(item.thirdManNum)
        return item
      });

      this.setData({
        tableData: this.data.tableData
      })
    },
    // 案件数量统计
    async getSxStatCountList() {
      let { content }: any = await getSxStatCountListAPI({ id: this.data.debtorId, businessType: this.data.businessType })
      // this.tableData = content;
      this.setData({
        tableData: content
      })
    }
  },
  observers: {
    'debtorId': function () {
      // console.log(this.data.debtorId, "debtorId")
      if (this.data.debtorId) {
        if (this.data.typeName === 'count') {
          this.getSxStatCountList()

        } else if (this.data.typeName === 'amount') {
          this.getSxStatAmountList()
        }

      }
    }
  },
})